package cn.accp.petShop;

import cn.accp.petShop.baseEntity.PetBase;
import cn.accp.petShop.baseEntity.Impl.Bird;
import cn.accp.petShop.baseEntity.Impl.Fish;
import cn.accp.petShop.entity.Cat;
import cn.accp.petShop.entity.Dog;

public class Demo {

	/**
	 * @param args
	 */
	// Dog is a pet,左父右子
	public static void main(String[] args) {

		demo0829();
	}

	//
	public static void demo0829() {
		PetBase pet = new Bird(1001, "菲菲", "麻雀", 70);
		pet.eat();
		pet.run();
		pet = new Fish(1002, "乐乐", "金鱼", 80);
		pet.eat();
		pet.run();
	}

	public static void play(PetBase pet) {
		pet.run();
		pet.eat();
	}

	public static void demo0828() {
		PetBase pet = new Dog(1002, "阿黄", "田园犬", 80, "黄色");
		pet.eat();// 子类重写了，调用是子类的版本
		pet.showMe();// 子类没重写，调用是父类，其实是子类的版本
		play(pet);
		pet = new Cat(1003, "咪咪", "波斯猫", 98);
		pet.eat();
		pet.showMe();
		play(pet);

		Cat cat = (Cat) pet;
		cat.catchMouse();
		cat.eat();
		cat.showMe();
		if (pet instanceof Dog) {
			Dog dog = (Dog) pet;
			dog.hunt();
		} else {
			System.out.println("Wrong type!");
		}
	}
}
